<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>wechat</title>
    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
</head>

<body>

</body>
<script>
    $(function () {
     //判断是否已经领取会员卡
         $.ajax({
                url: '/User/ExitCard',
                type: 'GET',
                success: function (data) {
                   if (data.Status == 1) 
                   //1代表没有存在卡，0代表存在卡
                        wxAddCard();
                 }
             });
    })
 
   //微信添加卡券
         function wxAddCard() {
 
              //微信sdk config
             wx.config({
                 debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                 appId: '', // 必填，公众号的唯一标识
                 timestamp: '', // 必填，生成签名的时间戳
                 nonceStr: '', // 必填，生成签名的随机串
                 signature: '',// 必填，签名，见附录1
                 jsApiList: ['onMenuShareTimeline',
                     'onMenuShareAppMessage',
                     'onMenuShareQQ',
                     'onMenuShareWeibo',
                     'onMenuShareQZone',
                     'startRecord',
                     'stopRecord',
                     'onVoiceRecordEnd',
                     'playVoice',
                     'pauseVoice',
                     'stopVoice',
                     'onVoicePlayEnd',
                     'uploadVoice',
                     'downloadVoice',
                     'chooseImage',
                     'previewImage',
                     'uploadImage',
                     'downloadImage',
                     'translateVoice',
                     'getNetworkType',
                     'openLocation',
                     'getLocation',
                     'hideOptionMenu',
                     'showOptionMenu',
                     'hideMenuItems',
                     'showMenuItems',
                     'hideAllNonBaseMenuItem',
                     'showAllNonBaseMenuItem',
                     'closeWindow',
                     'scanQRCode',
                     'chooseWXPay',
                     'openProductSpecificView',
                     'addCard',
                     'chooseCard',
                     'openCard'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
             });
 
                wx.ready(function () {
                    wx.addCard({
                        cardList: [{
                            cardId: '',
                            cardExt: '{"code":"","openid": "", "timestamp": "","nonce_str": "", "signature": ""}'
                        }],
                        success: function (res) {
                            $.ajax({
                                url: '/User/ActiveCard',
                                type: 'GET',
                                success: function (data) {
                                    if (data.Status == 0)
                                        alert("成功激活");
                                }
                            });
                        },
                        cancel: function (res) {
                            alert(JSON.stringify(res))
                        }
                    });
 
                });
 
         }
  </script>
</html>